import Toast from '@/wxcomponents/vant/toast/toast'

export const customToast = {
	$Toast(params, type) {
		if (!type) {
			Toast(params)
			return
		}
		if (Object.prototype.toString.call(params) === '[object Object]') {
			Toast[type](Object.assign({}, {
				duration: 1500,
				forbidClick: true
			}, params))
		} else {
			Toast[type](Object.assign({}, {
				message: params,
				duration: 1500,
				forbidClick: true
			}, params))
		}
	},
	success(params) {
		customToast.$Toast(params, 'success')
	},
	fail(params) {
		customToast.$Toast(params, 'fail')
	},
	text(params) {
		customToast.$Toast(params, null)
	},
	loading(params) {
		if (Object.prototype.toString.call(params) === '[object Object]') {
			customToast.$Toast(Object.assign({}, {
				duration: 0
			}, params), 'loading')
		} else {
			customToast.$Toast(Object.assign({}, {
				duration: 0,
				message: params
			}), 'loading')
		}
	},
	clear() {
		Toast.clear()
	}
}

export function showModal(params, callback) {
	let {
		title,
		content,
		showCancel,
		confirmText,
		cancelText,
	} = params;
	uni.showModal({
		title:title || '提示',
		content:content || '',
		showCancel:showCancel || true,
		confirmText:confirmText || '确定',
		cancelText:cancelText || '取消',
		confirmColor: '#02BF88',
		success(res) {
			if (res.confirm && typeof callback === 'function') {
				callback(true)
			}
			if (res.cancel && typeof callback === 'function') {
				callback(false)
			}
		},
		
	})
}
